﻿using Messhall.Domain.Permission.IRepositorys;
using Messhall.Framework.Domain.DomainService;

namespace Messhall.Domain.Permission.DomainServices;

public class PermissionDomainService : DomainServiceBase
{
    private readonly IPermissionRepository _permissionRepository;

    public PermissionDomainService(IPermissionRepository permissionRepository)
    {
        this._permissionRepository = permissionRepository;
    }

    public async Task<string> GetCode()
    {
        var maxCode = await _permissionRepository.FindMaxAsync(permiss => true, permiss => permiss.Code);

        if (maxCode == null)
        {
            return PermissionFactory.PERMISSION_DEFAULT_CODE;
        }

        return $"{int.Parse(maxCode) + 1}";
    }
}